package edu.hrbeu.NotePad;



import java.io.File;
import java.util.ArrayList;
import java.util.List;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.ListView;

public class ListNotes extends Activity {
	 public void onCreate(Bundle savedInstanceState) {
	        super.onCreate(savedInstanceState);
	        setContentView(R.layout.notelist);
	        ListView listView = (ListView)findViewById(R.id.listView1);
	        File file=new File("/data/data/edu.hrbeu.NotePad/files");
	       
	        final File[] filename= file.listFiles();
	        int i=0;
	        List<String> list  = new ArrayList<String>();

        	
	       for(i=0;i<filename.length;i++)
	        {
	        	String text=filename[i].getName().toString();
	        
	        	list.add(text);
	        }

	        ArrayAdapter<String> adapter = new ArrayAdapter<String>(this, 
	        		android.R.layout.simple_list_item_1, list );
	        listView.setAdapter(adapter);
			
			AdapterView.OnItemClickListener listViewListener = new AdapterView.OnItemClickListener(){
				@Override
				public void onItemClick(AdapterView<?> arg0, View arg1, int arg2, long arg3) {
				
					Intent intent=new Intent(ListNotes.this,ReadActivity.class);
					Bundle bundle =new Bundle();
					bundle.putString("param", filename[(int) arg3].getName().toString());
					intent.putExtras(bundle);
					startActivity(intent);
					
				}};
				
			listView.setOnItemClickListener(listViewListener);
	       
	        
	        
	 }

}
